
import com.alibaba.fastjson.JSON;
import com.aliyuncs.exceptions.ClientException;

import com.shigu.wx.web.WxTempleateBaseData;
import org.junit.Test;
import org.sword.wechat4j.api.WechatClient;
import org.sword.wechat4j.api.request.message.Cgi_binMessageTemplateSendPost;
import org.sword.wechat4j.api.response.message.MsgInfo;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Alimsg {
    /**
     * wechat.url=https://api.weixin.qq.com
     wechat.token=cailifukeji
     wechat.appid=wx3c0a3f9b28e6a836
     wechat.appsecret=29f70115b8cfbe4f4836465e6adc16eb
     * @param args
     * @throws ClientException
     * @throws IOException
     */
    @Test
    public void sendTest(){
//        System.out.println(SessionEnum.LOGIN_USER);
        Cgi_binMessageTemplateSendPost send=new Cgi_binMessageTemplateSendPost();
        send.setTemplate_id("1nyHrxd2LE_43KuDxu6gVHb32JiTcpjkJhAK2JMKpNA");
        send.setTouser("oitinxAnI2kCZWvJLP7EkSjEaVBg");//openid
        Map<String,WxTempleateBaseData> wxTempleateDataMap=new HashMap<String,WxTempleateBaseData>();
        wxTempleateDataMap.put("first",new WxTempleateBaseData("因为你傻，系统送你钱"));
        wxTempleateDataMap.put("keyword1",new WxTempleateBaseData("10000.00"));
        wxTempleateDataMap.put("keyword2",new WxTempleateBaseData("500.00"));
        wxTempleateDataMap.put("remark",new WxTempleateBaseData("详细请登陆查看"));
        send.setData(JSON.toJSONString(wxTempleateDataMap));
        send.setUrl("http://wxpublic.cailifu.net/wappage/agpage/tradeDetail");
        WechatClient client=new WechatClient("https://api.weixin.qq.com", "wx3c0a3f9b28e6a836", "29f70115b8cfbe4f4836465e6adc16eb", "cailifukeji");
        try {
            MsgInfo info=client.execute(send,"4_Q5BavZFsKe1qdNr7fp-xAhI96zvaSaIAsgbdRQtXXLJAKbsKbxJd9x-KZMN1lLyU882eWsfKa2hdvizxJAy3GitdZHoRVkqkhX5NokLv_RVdlVnoJ-6yNMh3cRsYUTiAGAFBA");
        } catch (IOException e) {
            e.printStackTrace();
        }
//        //产品名称:云通信短信API产品,开发者无需替换
//        final String product = "Dysmsapi";
//        //产品域名,开发者无需替换
//        final String domain = "dysmsapi.aliyuncs.com";
//
//        //
//        final String accessKeyId = "LTAIbo8ZlYNua2nl";
//        final String accessKeySecret = "d3BwbMfpcgwqPquAR4a27ocOzpS3GM";
//
//        //初始化acsClient,暂不支持region化
//        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
//        IAcsClient acsClient = new DefaultAcsClient(profile);
//
//        //组装请求对象-具体描述见控制台-文档部分内容
//        SendSmsRequest request = new SendSmsRequest();
//        //必填:待发送手机号
//        request.setPhoneNumbers("18888971970");
//        //必填:短信签名-可在短信控制台中找到
//        request.setSignName("财立付");
//        //必填:短信模板-可在短信控制台中找到
//        request.setTemplateCode("SMS_111580274");
//        //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
//        request.setTemplateParam("{\"code\":\"123456\"}");
//
//        //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
//        //request.setSmsUpExtendCode("90997");
//
//        //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//        request.setOutId("yourOutId");
//
//        //hint 此处可能会抛出异常，注意catch
//        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
    }
}
